﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace DanGao.Web.Areas.Manage.Controllers
{
    public class AccountController : Controller
    {
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public ActionResult Login()
        {
            return View();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="name"></param>
        /// <param name="password"></param>
        /// <param name="verStr"></param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult Login(string name, string password, string verStr)
        {
            if(ModelState.IsValid)
            {
                Admin admin = new Admin();
                if (name == admin.Name && password == admin.Password && verStr == admin.VerStr)
                {
                    System.Web.Security.FormsAuthentication.SetAuthCookie(admin.Name, true);
                    Session["User"] = admin;
                    return RedirectToAction("Index", "Home");
                }
            }
            return View();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public ActionResult Logout()
        {
            System.Web.Security.FormsAuthentication.SignOut();
            Session["User"] = null;
            return RedirectToAction("Index", "Home");
        }

    }

    public class Admin
    {
        private string name = "luoliang";
        private string password = "19861217";
        private string verStr = "1234";

        /// <summary>
        /// 管理员名称
        /// </summary>
        public string Name 
        { 
            get
            {
                return name;
            }
        }

        /// <summary>
        /// 管理员密码
        /// </summary>
        public string Password
        {
            get
            {
                return password;
            }
        }

        /// <summary>
        /// 验证码
        /// </summary>
        public string VerStr
        {
            get
            {
                return verStr;
            }
        }

    }
}
